package com.example.day09_actionbardemo;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter{

	private List<String>datas;
	private LayoutInflater inflater;
	public MyAdapter(Context context,List<String> datas) {
		super();
		
		this.datas = datas;
		inflater=LayoutInflater.from(context);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datas.size();
	}
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return datas.get(position);
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView==null){
			convertView=inflater.inflate(R.layout.layout_item, null);
			holder=new ViewHolder();
			holder.tv=(TextView)convertView.findViewById(R.id.tv);
			convertView.setTag(holder);
		}else {
			holder=(ViewHolder)convertView.getTag();
		}
		
		holder.tv.setText(datas.get(position));
		return convertView;
	}
	private class ViewHolder{
		TextView tv;
	}
}
